#include <stdio.h>

#  define M_PI          3.14159265358979323846

double angles[23],
  shiftamt[23];

sincos(double testangle,double* cosptr,double* sinptr){

  double ztemp,
    xtemp,
    ytemp,
    x,
    y,
    z;
  
  int i,
    d;

  ztemp = testangle;
  xtemp = 1;
  ytemp = 0;
  
  for (i=0;i<23;i++){
    if (ztemp < 0)
      d = -1;
    else
      d = 1;
    
    x = xtemp - ytemp*d*shiftamt[i];
    y = ytemp + xtemp*d*shiftamt[i];
    z = ztemp - d*angles[i];
    xtemp = x;
    ytemp = y;
    ztemp = z;
    
  }
  
  *sinptr = y / 1.64676025812105; 
  *cosptr = x / 1.64676025812105;
  
}

 
int main()
{
  double* sinptr;
  double* cosptr;

  double testangle;
    
  double totalsin,
    totalcos; 

  double a,
    j,
    x,
    xtemp,
    y,
    ytemp,
    z,
    ztemp;
  double sinans,
    cosans;
  
  int i,
      d;
      
  angles[0]=0.785398163397448;
  angles[1]=0.463647609000806;
  angles[2]=0.244978663126864;
  angles[3]=0.124354994546761;
  angles[4]=0.0624188099959574;
  angles[5]=0.0312398334302683;
  angles[6]=0.0156237286204768;
  angles[7]=0.00781234106010111;
  angles[8]=0.00390623013196697;
  angles[9]=0.00195312251647882;
  angles[10]=0.000976562189559319;
  angles[11]=0.000488281211194898;
  angles[12]=0.000244140620149362;
  angles[13]=0.00012207031189367;
  angles[14]=6.10351561742088e-05;
  angles[15]=3.05175781155261e-05;
  angles[16]=1.52587890613158e-05;
  angles[17]=7.62939453110197e-06;
  angles[18]=3.8146972656065e-06;
  angles[19]=1.90734863281019e-06;
  angles[20]=9.53674316405961e-07;
  angles[21]=4.76837158203089e-07;
  angles[22]=2.38418579101558e-07;

  shiftamt[0]=1;
  shiftamt[1]=0.5;
  shiftamt[2]=0.25;
  shiftamt[3]=0.125;
  shiftamt[4]=0.0625;
  shiftamt[5]=0.03125;
  shiftamt[6]=0.015625;
  shiftamt[7]=0.0078125;
  shiftamt[8]=0.00390625;
  shiftamt[9]=0.001953125;
  shiftamt[10]=0.0009765625;
  shiftamt[11]=0.00048828125;
  shiftamt[12]=0.000244140625;
  shiftamt[13]=0.0001220703125;
  shiftamt[14]=6.103515625e-05;
  shiftamt[15]=3.0517578125e-05;
  shiftamt[16]=1.52587890625e-05;
  shiftamt[17]=7.62939453125e-06;
  shiftamt[18]=3.814697265625e-06;
  shiftamt[19]=1.9073486328125e-06;
  shiftamt[20]=9.5367431640625e-07;
  shiftamt[21]=4.76837158203125e-07;
  shiftamt[22]=2.38418579101562e-07;
  
  sinptr = &sinans;
  cosptr = &cosans;
  
  totalsin = 0;
  totalcos = 0;

  for (j=-89.999;j<90;j+=.001){
    testangle = j / 180 * M_PI;
    /* printf("%f\n",testangle); */
    
    sincos(testangle,cosptr,sinptr);
    
    totalsin += sinans;
    totalcos += cosans;

    /*printf("sin(%f) = %f\n",testangle,sinans);
    printf("cos(%f) = %f\n",testangle,cosans);
    printf("%f\n",z);*/
    
  }
  
  printf("aggregate sin = %f\n",totalsin);
  printf("aggregate cos = %f\n",totalcos);
  /*.60725293510314 */

}











